package edu.jd.movieplatform.search.m_point;


import edu.jd.movieplatform.common.Result;
import edu.jd.movieplatform.info.movie.MovieDto;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.List;

@RestController
@RequestMapping("/search/m_point")
public class m_PointAPI {
    @Resource
    private m_PointService pointService;

    @PostMapping("/point")
    public Result Point(@RequestBody mov_idDto dto) {
        Integer mov_id=dto.getMov_id();
        List<m_Point> list = pointService.getMoviePoint(mov_id);
        float point = 0;
        for (int i = 0; i < list.size(); i++) {
            point = point + list.get(i).getCom_score();
        }
        point = point / list.size();
        BigDecimal b = new BigDecimal(point);
        float m_point = b.setScale(2, RoundingMode.HALF_UP).floatValue();
        pointService.updateMoviePoint(mov_id, m_point);
        return Result.success();
    }
}
